/**
 * 
 */
package us.gaaoc.framework.dao;

import org.hibernate.Query;

import us.gaaoc.framework.model.DocumentInstance;
import us.gaaoc.framework.model.DocumentLocalCode;

/**
 * 
 * @author hea
 * May 18, 2007
 */
public class DocumentLocalCodeDAOHibernate extends GenericHibernateDAO<DocumentLocalCode, Integer, DocumentLocalCodeDAO>
implements  DocumentLocalCodeDAO{
	
	public DocumentLocalCode findDocumentLocalCodeFromDocumentInstanceCode(
			int documentInstanceCode) {
		LOG.debug("Inside the findDocumentLocalCodeFromDocumentInstanceCode method ");
		Query q = this.getSession().createQuery(
				"from DocumentInstance di where di.code = ? ");
		q.setInteger(0, documentInstanceCode);
		DocumentInstance documentInstance = (DocumentInstance)q.uniqueResult();
		DocumentLocalCode docLocalCode = new DocumentLocalCode();
		docLocalCode.setCode(documentInstance.getDocLocalCode().getCode());
		docLocalCode.setDescription(documentInstance.getDocLocalCode().getDescription());
		LOG.info("The documnet local code of the document instance "+documentInstance.getDescription()+" is "+docLocalCode.getCode());
		return docLocalCode;

	}
}
